import { useState } from 'react';

export default function User() {
  const search: any = new URLSearchParams(location.search);
  search?.get('openid') &&
    localStorage.setItem('openid', search?.get('openid'));

  const [openid, setOpenid] = useState<string>(
    search?.get('openid') || (localStorage.getItem('openid') as string),
  );

  function updateOpenid(id: string) {
    !openid && setOpenid(id);
    localStorage.setItem('openid', id);
  }

  return {
    openid,
    updateOpenid,
  };
}
